package cn.source.system.Utils;

import cn.source.system.service.Command;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class PutLTFSCommand implements Command {

    private String command;
    public PutLTFSCommand(String command) {
        this.command = command;
    }

  //  "C:\Users\My-PC\Desktop\Redis-x64-3.2.100\redis-server.exe"
    @Override
    public void execute() {
        try {
            // 创建Runtime对象
            Runtime runtime = Runtime.getRuntime();

            // 运行命令行命令
            Process process = runtime.exec("C:\\Users\\My-PC\\Desktop\\Redis-x64-3.2.100\\redis-server.exe");

            // 读取命令行输出
            InputStream inputStream = process.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }

            // 等待命令行进程执行完毕
            int exitCode = process.waitFor();
            System.out.println("命令执行完毕，退出码为: " + exitCode);

        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
